<?php

namespace app\admin\controller;

use Carbon\Carbon;
use think\helper\Time;

class Tongji extends Admin
{
    private $tongji='';
    public function logic(){
        if(empty($this->tongji)){
            $this->tongji = new \app\common\logic\Tongji();
        }
        return $this->tongji;
    }

    /**
     * 渠道建单统计
     * @return mixed
     */
    public function index()
    {

        return $this->fetch();
    }

    /**
     *预产期统计
     */
    public function ycqtj(){
        $times = $this->request->param();
        $this->assign('times',$times);
        $jdtime = $times['jdtime'];
        unset($times['jdtime']);
        $map['status'] = 1;
        $map['yiyuan'] = ['neq',0];
        if(!empty($jdtime)){
            $jdtime = Carbon::parse($jdtime);
            $map['jdtime'] = ['between',[strtotime($jdtime->startOfMonth()->toDateTimeString()), strtotime($jdtime->endOfMonth()->toDateTimeString())]];
        }
        $months = $this->logic()->getTime($times);
        $map['yctime'] = ['between',[$months[0]['start'], end($months)['end']]];
        $data = $this->logic()->tongjiycq($map,$months);
        $this->assign('months',$months);
        $this->assign('data',$data);
        return $this->fetch('ycqtj');
    }

}
